<?php 

//@TODO extraer esto a un método privado
foreach($this->_dataBaseSource['fields'] as $key => $value) {
    if(!is_numeric($key)) {
        $paramString .= '"' . $key . '" => "' . $value .'"';
    } else {
        $paramString .= '"' . $value . '"';
    }
    $paramString .= ', ';
}

$sqlCode = '
<?php
$select = new SimpleSelect();
$select->select(array(' . $paramString . '))
        ->from("' . $this->_dataBaseSource['tableName'] . '");
$optionData = $select->getResultsAsObjectArray();
?>';
?>

<div class="formElement">
    <label for="<?php echo $this->_id ?>"><?php echo $this->_label ?>:
        <?php echo $sqlCode; ?>
        <select name="send[<?php echo $this->_formName; ?>]" 
                id="<?php echo $this->_id ?>" 
                class="fancy <?php echo implode(" ", $this->_cssClasses) ?>" >
            <?php
            $valueField = $this->_dataBaseSource['mappedFields']['value'];
            $textField = $this->_dataBaseSource['mappedFields']['text'];
            echo '<?php
            foreach ($optionData as $option) {
                $value = $option->' . $valueField . ';
                $text = $option->' .$textField . ';
                $checked = ($data["' . $this->_dbFieldName . '"] ==  $value ) ? "' . self::SELECTED_STRING . '" : "";
                ?>
                <option <?php echo $checked; ?> value="<?php echo $value; ?>"><?php echo $text; ?></option>
            <?php } ?>';
            
            ?>
        </select>
    </label>
</div>
